home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / IRQ.ASM < prev    next >
Assembly Source File  |  1994-06-22  |  10KB  |  361 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ;
  3. ; Filename     : Irq.asm
  4. ; Included from: Main Assembley Module
  5. ; Description  : Irq handler for timing/tracking vertical retrace
  6. ;
  7. ; Written by: John McCarthy
  8. ;             1316 Redwood Lane
  9. ;             Pickering, Ontario.
  10. ;             Canada, Earth, Milky Way (for those out-of-towners)
  11. ;             L1X 1C5
  12. ;
  13. ; Internet/Usenet:  BRIAN.MCCARTHY@CANREM.COM
  14. ;         Fidonet:  Brian McCarthy 1:229/15
  15. ;   RIME/Relaynet: ->CRS
  16. ;
  17. ; Home phone, (905) 831-1944, don't call at 2 am eh!
  18. ;
  19. ; John Mccarthy would really love to work for a company programming Robots
  20. ; or doing some high intensive CPU work.  Hint. Hint.
  21. ;
  22. ; Send me your protected mode source code!
  23. ; Send me your Objects!
  24. ; But most of all, Send me a postcard!!!!
  25. ;
  26. ; This uses irq 8 set to the same speed as the vertical retrace so that
  27. ; an animation will remain at a smooth/constant speed regardless of the
  28. ; machine speed: eg, a 386SX33 will run an animation at the same  speed
  29. ; as a 486DX66, only the 386 will skip frames to compensate.All the irq
  30. ; really does is "inc traces_past" and this information is used to skip
  31. ; frames. If traces_past =1 is 486DX66, =4 is 386 or whatever.  You get
  32. ; the idea right?
  33. ;
  34. ; The irq can operate in real mode or pmode.  Just call the appropiate
  35. ; routine.  I did this in case you want to add to  the  irq  your  own
  36. ; functions for sound or music or whatever.
  37. ;
  38. ; Protected mode IRQ controled  subroutines  are  not  available  when
  39. ; using the real mode IRQ (obviosly)
  40. ;
  41. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  42.  
  43.         .386p
  44.         jumps
  45.  
  46.         public set_pmirq
  47.         public reset_pmirq
  48.  
  49.         public set_rmirq
  50.         public reset_rmirq
  51.  
  52.         public reset_raster_count
  53.         public time_raster
  54.  
  55.         public frametime
  56.  
  57.         public traces_past
  58.         public frame_number
  59.  
  60.         public _irqcontrol0
  61.         public _irqcontrol1
  62.         public _irqcontrol2
  63.         public _irqcontrol3
  64.         public _irqcontrol4
  65.         public _irqcontrol5
  66.         public _irqcontrol6
  67.         public _irqcontrol7
  68.  
  69.         include 3d.ext
  70.         include equ.inc
  71.  
  72.         pmodeirq equ 0  ; you could also use irq 8 for either of these.
  73.         rmodeirq equ 8  ; both can run at the same time even if both=0.
  74.  
  75. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  76. ; Real mode IRQ handler
  77. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  78.  
  79. code16  segment para public use16
  80.         assume cs:code16, ds:code16
  81.  
  82. rmirq0:                             ; real mode IRQ0 handler
  83.         push ax ds
  84.  
  85. ; put your real mode irq code here!!!!!
  86. ;--------------------------------------
  87.  
  88.  
  89.  
  90. ;--------------------------------------
  91.  
  92. ; now my code, this is where i inc that variable
  93. ; real mode irq increments protected mode memory location
  94.  
  95.         mov ax,cs:rfs
  96.         mov ds,ax
  97.         mov si,cs:rfo
  98.  
  99.         inc dword ptr [si]          ; inc traces_past
  100.         inc dword ptr [si+4]        ; inc frame_number
  101.  
  102.         pop ds
  103.         mov al,20h
  104.         out 20h,al
  105.         pop ax
  106.  
  107.         iret
  108.  
  109. rfs     dw ?                        ; data segment for traces_past
  110. rfo     dw ?                        ; di offset for traces_past
  111.  
  112. transfer_location:
  113.         mov cs:rfs,cx               ; set protected mode location of
  114.         mov cs:rfo,dx               ; traces_past in terms of real mode
  115.         ret
  116.  
  117. code16  ends
  118.  
  119. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  120.  
  121. code32  segment para public use32
  122.         assume cs:code32, ds:code32
  123.  
  124.         include pmode.ext
  125.  
  126. ormirq0 dd ?                        ; old real mode IRQ handler seg:off
  127. opmirq0 dd ?                        ; old protected mode IRQ handler off
  128.  
  129. traces_past   dd 0                  ; contains frame speed (irq driven)
  130. frame_number  dd 0                  ; number of frames total,eg 23400 = 13 mins
  131.  
  132. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  133. ; Protected mode IRQ handler
  134. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  135.  
  136. pmirq0:                             ; protected mode IRQ0 handler
  137.         pushad
  138.  
  139. ; put your protected mode irq code here!!!!!
  140. ;-------------------------------------------
  141.  
  142.  
  143.  
  144. ;-------------------------------------------
  145.  
  146. ; now my code, this is where i inc that variable
  147. ; protected mode version is easy!
  148.  
  149.         inc traces_past
  150.         inc frame_number
  151.  
  152.         call [d _irqcontrol0]       ; call selected IRQ subroutines
  153.         call [d _irqcontrol1]
  154.         call [d _irqcontrol2]
  155.         call [d _irqcontrol3]
  156.         call [d _irqcontrol4]
  157.         call [d _irqcontrol5]
  158.         call [d _irqcontrol6]
  159.         call [d _irqcontrol7]
  160.         popad
  161.  
  162.         jmp cs:opmirq0              ; chain to old IRQ0 redirector
  163.  
  164. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  165. ; Set_rmirq: Get real mode IRQ going
  166. ; In=Out=Null
  167. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  168.  
  169. set_rmirq:
  170.         mov eax,gs:[rmodeirq*4]     ; save real mode IRQ0 vector
  171.         mov ormirq0,eax
  172.  
  173.         cli                         ; set IRQ0 to inc variable
  174.  
  175.         mov word ptr gs:[rmodeirq*4],offset rmirq0  ; set real mode irq
  176.         mov word ptr gs:[(rmodeirq*4)+2],code16
  177.  
  178.         mov edx,offset traces_past  ; tell real mode irq where traces_past
  179.         add edx,_code32a            ; is in memory (pmode location)
  180.         mov al,dl
  181.         and ax,0fh
  182.         shr edx,4
  183.         mov v86r_cx,dx
  184.         mov v86r_dx,ax
  185.  
  186.         mov cx,seg transfer_location
  187.         mov dx,offset transfer_location
  188.         int 32h
  189.  
  190.         sti
  191.  
  192.         jmp new_timer
  193.  
  194. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  195. ; Reset_rmirq: Unhook real mode IRQ and reset original timer
  196. ; In=Out=Null
  197. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  198.  
  199. reset_rmirq:
  200.         cli
  201.  
  202.         mov eax,ormirq0             ; restore old real mode IRQ0 vector
  203.         mov gs:[rmodeirq*4],eax
  204.  
  205.         sti
  206.  
  207.         jmp old_timer
  208.  
  209. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  210. ; Set_pmirq: Get protected mode IRQ going
  211. ; In=Out=Null
  212. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  213.  
  214. set_pmirq:
  215.         xor bl,bl                   ; get protected mode IRQ0 redirector
  216.         call _getirqvect
  217.         mov opmirq0,edx
  218.  
  219.         cli                         ; set IRQ0 to inc variable
  220.  
  221.         mov bl,pmodeirq
  222.         mov edx,offset pmirq0
  223.         call _setirqvect            ; set protected mode irq
  224.  
  225.         sti
  226.  
  227.         jmp new_timer
  228.  
  229. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  230. ; Reset_pmirq: Unhook protected mode IRQ and reset original timer
  231. ; In=Out=Null
  232. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  233.  
  234. reset_pmirq:
  235.         cli
  236.  
  237.         mov bl,pmodeirq
  238.         mov edx,opmirq0
  239.         call _setirqvect
  240.  
  241.         sti
  242.  
  243.         jmp old_timer
  244.  
  245. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  246. ; Set Irq speed to match retrace time
  247. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  248.  
  249. new_timer:
  250.         call time_raster
  251.  
  252.         cli
  253.         mov al,36h
  254.         out 43h,al
  255.         mov ax,frametime
  256.         out 40h,al
  257.         mov al,ah
  258.         out 40h,al
  259.         sti
  260.  
  261.         ret
  262.  
  263. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  264. ; Reset Irq speed to default speed
  265. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  266.  
  267. old_timer:                         ; reset timer for exit
  268.         cli
  269.         mov al,36h
  270.         out 43h,al
  271.  
  272.         mov ax,0
  273.         out 40h,al
  274.         out 40h,al
  275.  
  276.         sti
  277.  
  278.         ret
  279.  
  280. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  281. ; Reset_raster_count: reset counters (done before anmation loop)
  282. ; In=Out=Null
  283. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  284.  
  285. reset_raster_count:                ; reset count before any animation loop
  286.         cli
  287.         mov traces_past,1
  288.         mov frame_number,0
  289.         sti
  290.         ret
  291.  
  292. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  293. ; Time_raster: Guess what this does?
  294. ; In=Null
  295. ; Out:
  296. ;   AX=time for raster to occure
  297. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  298.  
  299. frametime dw 4276h
  300.  
  301. time_raster:
  302.         cli
  303.         mov dx, input_1        ; input# 1 reg
  304. loop1:
  305.         in al,dx               ; wait for vsync
  306.         test al,8
  307.         jnz loop1
  308. loop2:
  309.         in al,dx
  310.         test al,8
  311.         jz loop2
  312.  
  313.         mov al,36h             ; reset timer
  314.         out 43h,al
  315.         mov al,0
  316.         out 40h,al
  317.         mov al,0
  318.         out 40h,al
  319. loop3:
  320.         in al,dx               ; wait for vsync
  321.         test al,8
  322.         jnz loop3
  323. loop4:
  324.         in al,dx
  325.         test al,8
  326.         jz loop4
  327.  
  328.         xor al,al              ; this calculation code courtesy future_crew
  329.         out 43h,al             ; from mental.exe
  330.         in al,40h
  331.         mov ah,al
  332.         in al,40h
  333.         xchg al,ah
  334.         neg ax
  335.         shr ax,1
  336.         mov frametime,ax
  337.  
  338.         sti
  339.         ret
  340.  
  341. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  342. ; These are the user difinable IRQ controlled jump vectors:
  343. ;
  344. ; You can have a certine function performed every  vertical retrace just
  345. ; by setting these to point to the code you wish to  be   called.   When
  346. ; you want to disable the subroutine, just reset these vectors to offset
  347. ; _ret.
  348. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  349.  
  350. _irqcontrol0 dd offset _ret
  351. _irqcontrol1 dd offset _ret
  352. _irqcontrol2 dd offset _ret
  353. _irqcontrol3 dd offset _ret
  354. _irqcontrol4 dd offset _ret
  355. _irqcontrol5 dd offset _ret
  356. _irqcontrol6 dd offset _ret
  357. _irqcontrol7 dd offset _ret
  358.  
  359. code32  ends
  360.         end
  361.